/*** Class Name: OORTeleSalesLeadEmailHandlerTest
 * Author: Accenture
 * Date: 17-April-2012
 * Requirement/Project Name: OORTeleSales
 * Requirement Description: Test class for OORTeleSalesLeadEmailHandler
 **/

@istest(seealldata=true)
private  class OORTelesalesLeadEmailHandlerTest
{

 /*
  *  Test method 
  **/
  static testMethod void leadEmailServTest() 
  {
  
     Profile pro = [select id from profile where name='System Administrator'];
     User usr = new User(alias = 'sysad', email='sysadmin@accenture.com',emailencodingkey='UTF-8', lastname='Tes12', languagelocalekey='en_US',localesidkey='en_US', profileid = pro.Id,timezonesidkey='Asia/Calcutta', username='testad123@testorg.com');
     Insert usr;     
  
     Messaging.InboundEmail email = new Messaging.InboundEmail() ;
     Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
     env.fromAddress = 'user@acme.com';
     ID localAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeIdByDevName('Lead', OORTelesalesTextConstant.LOCAL_ADVERTISER_LEAD_REC_TYPE);   
     
     Lead  le  = new Lead(FirstName='testFirstName',LastName = 'ash', company='ABc',Lead_Status_ReadOnly__c = 'New' ,Status='New',RecordTypeId= localAdvertiserRecordTypeID );
     insert le;
      
      email.subject = 'Lead Id' + le.id;
      // add an attachment
      Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
      attachment.body = blob.valueOf('my attachment text');
      attachment.fileName = 'textfile.txt';
      attachment.mimeTypeSubType = 'text/plain';
 
      email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment };
     
      Messaging.InboundEmail.TextAttachment textAttachment = new Messaging.InboundEmail.TextAttachment();
      textAttachment.body ='my attachment text';
      textAttachment.fileName = 'textfile.txt';
      textAttachment.mimeTypeSubType = 'text/plain';
 
      email.textAttachments= new Messaging.inboundEmail.TextAttachment[] { textAttachment };
      
     // Call the class and test it with the data in the test method.
     OORTeleSalesLeadEmailHandler leadEmailHandler = new OORTeleSalesLeadEmailHandler();
     leadEmailHandler.handleInboundEmail(email, env );
     email.subject = 'Lead id-';
     email.plainTextBody = 'For system use only, DO NOT DELETE Lead -'  + le.id;
     leadEmailHandler.handleInboundEmail(email, env ); 
   
   
   
  }
}